<?php

class Provider extends Eloquent {
    protected $table = 'provider';


    public static function ListProvider($shop_id)
    {        
          try{
            
          
          $query_select=" SELECT * FROM provider WHERE shop_id = '$shop_id' ";
            return DB::select(DB::raw($query_select));
                        
          
        }
        catch(Exception $e)
        {
            throw $e;
        }

    }
    
    
    
    public static function  Insert( $shop_id,$name, $address, $phone, $website, $email, $comments){
        

        try{
            $provider= new Provider();
            $provider->shop_id = $shop_id;
            $provider->name = $name;
            $provider->address =$address;
            $provider->phone=$phone;
            $provider->website=$website;
            $provider->email=$email;
            $provider->comments=$comments;
            $provider->save();
            $provider_id = $provider->id;
            return $provider_id;
        }
        catch(Exception $e)
        {
            throw $e;
        }
        
    }
    
    
    
    
    public static function Edit($name, $address, $phone, $website, $email, $comments,$provider_id)
    {
        try{
            $query_update="UPDATE provider 
                                    SET updated_at=CURRENT_TIMESTAMP,
                                    
                                    name= '$name',
                                    address ='$address',
                                    phone = '$phone',
                                    website = '$website' ,
                                    email = '$email' ,
                                    comments = '$comments'
                                    
                                    WHERE id='$provider_id'";
                                     
                                                          
                                        

             //echo $query_update;
            DB::update($query_update);
            return true;
        }
        catch(Exception $e)
        {
            throw $e;
        }
             
      }
      
      
      
      
       public static function Del($provide_id)
        {
            try{
                      
                DB::table('provider')->where('id','=',$provide_id)->delete();
                return true;
            }
            catch(Exception $e)
            {
                throw $e;
            }
        }
    
      

  }

?>